/**
 * Sistema $$$$ de Suburbans
 *
 * @author    Ing. José Armando González López
 * @copyright (c) 2008, por Ing. José Armando González López
 * @date      16. Febrero 2009
 * @version   $Id$
 * @basado 	En el toaster de Edouard Fattal
 * @license Manduks.Notificacion.js by "manduks" 
 * http://www.mahuiztik.com
 */
Ext.namespace("Manduks.Notificacion");

Manduks.Notificacion.Vector = {
	positions: []
};

Manduks.Notificacion.Toaster = Ext.extend(Ext.Window, {
	initComponent: function(){
		var config={
			tipo:this.tipo || 'info',
			iconCls:this.tipo,
			cls: 'x-notification',
			dirShow:this.dirShow || 'b',
			dirHide:this.dirHide || 'b',
			posicion:this.posicion || 'br-br',
			width: 200,
			autoHeight: true,
			plain: false,
			draggable: false,
			bodyStyle: 'text-align:center'
		};//fin config
		//apply config
 		Ext.apply(this,Ext.apply(this.initialConfig,config));
 		
		if(this.autoDestroy) {
			this.task = new Ext.util.DelayedTask(this.hide, this);
		} else {
			this.closable = true;
		}
		Manduks.Notificacion.Toaster.superclass.initComponent.call(this);
	},
	setMessage: function(msg){
		this.body.update(msg);
	},
	setTitle: function(title, iconCls){
		Manduks.Notificacion.Toaster.superclass.setTitle.call(this, title, iconCls||this.iconCls);
	},
	onRender:function(ct, position) {
		Manduks.Notificacion.Toaster.superclass.onRender.call(this, ct, position);
	},
	onDestroy: function(){
		Manduks.Notificacion.Vector.positions.remove(this.pos);
		Manduks.Notificacion.Toaster.superclass.onDestroy.call(this);
	},
	cancelHiding: function(){
		this.addClass('fixed');
		if(this.autoDestroy) {
			this.task.cancel();
		}
	},
	afterShow: function(){
		Manduks.Notificacion.Toaster.superclass.afterShow.call(this);
		Ext.fly(this.body.dom).on('click', this.cancelHiding, this);
		if(this.autoDestroy) {
			this.task.delay(this.hideDelay || 5000);
	   }
	},
	animShow: function(){
		this.pos = 0;
		while(Manduks.Notificacion.Vector.positions.indexOf(this.pos)>-1)
			this.pos++;
		Manduks.Notificacion.Vector.positions.push(this.pos);
		this.setSize(200,100);
		this.el.alignTo(document, this.posicion, [ -20, -20-((this.getSize().height+10)*this.pos) ]);
		this.el.slideIn(this.dirShow, {
			duration: 1,
			callback: this.afterShow,
			scope: this
		});
	},
	animHide: function(){
		   Manduks.Notificacion.Vector.positions.remove(this.pos);
		this.el.ghost(this.dirHide, {
			duration: 1,
			remove: true
		});
	},

	focus: Ext.emptyFn 
});
//lazy render





 //Ext.reg('notificacion', Manduks.Notificacion.Toaster);
